Skip to content

Fix a minor issue with the datepicker.#2944

Open
drgrice1 wants to merge 1 commit intoopenwebwork:WeBWorK-2.21from
drgrice1:bugfix/datepicker
Open

Fix a minor issue with the datepicker.#2944
drgrice1 wants to merge 1 commit intoopenwebwork:WeBWorK-2.21from
drgrice1:bugfix/datepicker

Conversation

@drgrice1
Copy link
Copy Markdown
Member

@drgrice1 drgrice1 commented Apr 7, 2026

With the current code if you are in a month that does not have a day (such as April that does not have the 31st), one of those days is selected in another month that does have that day, and you click the "Today" button, then it doesn't go to today. Instead it goes to the date of today in the next month. This is because the code sets the year, month, and day for today on the selected date object and in that order, and uses the modified selected date to set the flatpickr date. So for example, if today is April 7, 2026, and the selected date is July 31, 2026, then the selected date's year is set to 2026, then the month set to April. So at that point the selected date is April 31, 2026, which really becomes May 1, 2026. Then the day is set, and so you get May 7, 2026.

This fixes the issue by starting with todays date at 12:00 am, and then setting the time of todays date to the time of the selected date, and then using that to set the flatpickr date.

With the current code if you are in a month that does not have a day
(such as April that does not have the 31st), one of those days is
selected in another month that does have that day, and you click the
"Today" button, then it doesn't go to today.  Instead it goes to the
date of today in the next month.  This is because the code sets the
year, month, and day for today on the selected date object and in that
order, and uses the modified selected date to set the flatpickr date.
So for example, if today is April 7, 2026, and the selected date is July
31, 2026, then the selected date's year is set to 2026, then the month
set to April.  So at that point the selected date is April 31, 2026,
which really becomes May 1, 2026.  Then the day is set, and so you get
May 7, 2026.

This fixes the issue by starting with todays date at 12:00 am, and then
setting the time of todays date to the time of the selected date, and
then using that to set the flatpickr date.
@drgrice1 drgrice1 force-pushed the bugfix/datepicker branch from 70187c6 to df014ba Compare April 8, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants